package com.glory.dmegcpda.viewmodel

import androidx.databinding.ObservableArrayList
import com.glory.dmegcpda.R
import com.glory.dmegcpda.bean.LotInfoDownLoadBean
import com.glory.dmegcpda.bean.MLotListBean
import com.glory.dmegcpda.model.LotInventoryRepository
import com.glory.dmegcpda.model.QualityCheckRepository
import com.glory.mvvmnet.base.BaseViewModel
import com.glory.mvvmnet.entity.CallObserveBean
import com.glory.mvvmnet.entity.ToastMessageBean
import com.google.gson.JsonObject
import me.tatarka.bindingcollectionadapter2.BR
import me.tatarka.bindingcollectionadapter2.ItemBinding

/**
 * FileName: LotInventoryViewModel
 * Author: XJH
 * Date: 2021/10/20 17:12
 * Description:
 * History:
 */
class LotInventoryViewModel : BaseViewModel() {

    val lotTitle = arrayListOf("No.","托盘号","数量")
    private val lotInventoryRepository by lazy { LotInventoryRepository() }

    //物料列表
    var mLotItems = ObservableArrayList<LotInfoDownLoadBean>()
    var mMaterielBinding =
        ItemBinding.of<LotInfoDownLoadBean>(BR.mLotInventoryItem, R.layout.item_lot)

    fun getLotInfo(lot: String) {
        val map = JsonObject()
        map.addProperty("LOTID", lot)
        launchOnlyResult({
            val lotInfo = lotInventoryRepository.getLotInfo(map)
            lotInfo.position = (mLotItems.size + 1).toString()
            mLotItems.add(lotInfo)
        })
    }

    fun inventory(lot: String){
        val map = JsonObject()
        map.addProperty("LOTID", lot)
        launchOnlyResult({
            lotInventoryRepository.lotInventory(map)
            defUI.toastEvent.value = ToastMessageBean("入库成功",true)
            mLotItems.clear()
            defUI.callObserve.call()
        })
    }


}